/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session.stateless;

import java.util.Collection;
import javax.ejb.Stateless;
import javax.ejb.EJB;
import persistence.entity.Account;
import persistence.entity.Customer;

/**
 *
 * @author Dotke
 */
@Stateless
public class CustomerHelperBean implements CustomerHelperBeanRemote {
    @EJB
    private AccountFacadeRemote accountFacade;
    @EJB
    private AccountHelperLocal accountHelper;
    @EJB
    private CustomerFacadeRemote customerFacade;

    @Override
    public Boolean removeCustomer(int id) {
       Customer cust = customerFacade.find(id);
        cust.setIsdisabled(Boolean.TRUE.toString());       
        try {
            customerFacade.edit(cust);
            //Disable all accounts
            Collection<Account> accounts = accountFacade.getAccountList(id, true);
            for (Account acc : accounts) {
                accountHelper.disableAccountLocal(acc.getAccountId());
            }
            return true;
        } catch(Exception e) {
            System.out.println(e.getMessage());
        }
        
        return false;
    }
    
    

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    
    
}
